<template>
	<view class="page">
		<view class="order">
			<tab-title :tabTitle="title"></tab-title>
			<view class="tab">
				<my-tab :modelData="tabList" @change="handleChange"></my-tab>
			</view>
		</view>		
				<view class="">
					<block v-for="(item, index) in orderList" :key="item.id">
						<order-item
						:orderid="item.id"
						:name="item.nickName"
						:title="item.orderName"
						:orderNo="item.orderNo"
						:listResult="item.listResult"
						:status="item.status"
						:offTime="item.offTime"
						:createTime="item.createTime"
						:total="item.orderPrice"
						></order-item>
					</block>
				</view>

		</view>
	</view>
	
</template>

<script>
	import myTab from '@/components/myTab/myTab.vue'
	import orderItem from '@/components/order/orderItem.vue'
	import {isLogin} from '@/common/checkLogin.js'
	export default {
		data() {
			return {
				title:'商品列表',
				tabList:[{
					label:'全部',
					status:''
				},{
					label:'待付款',
					status:'0'
				},
				{
					label:'待收货',
					status:'1'
				},
				{
					label:'待评价',
					status:'2'
				},
				{
					label:'以完成',
					status:'3'
				},{
					label:'已取消',
					status:'4'
				}],
				status:'',
				currentPage: 0, //分页参数当前页面
				pages: 0, //分页总数
				orderList:[
					
				]
			}
		},
		onLoad() {
			if(!uni.getStorageSync('userInfo')){
				uni.redirectTo({
					url:'/pages/login/login'
				})
			}
		},
			onPullDownRefresh() {
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
				const curpage = (this.currentPage - 0) + 1;
				if (curpage <= this.pages) {
					uni.showLoading({
						title: '正在加载...'
					})
					this.currentPage = curpage;
					this.getStoreList(curpage)
				} else {
					uni.showToast({
						title: '没有更多了',
						icon: 'none'
					})
				}
		},
		onShow() {
			this.getStoreList()
		},
		methods: {
			handleChange(obj){
				let status = obj.status;
				this.status = status;
				this.currentPage = '0';
				this.orderList = [];
				this.getStoreList()
			}
			,
			getStoreList(pageNo='0'){
				let userInfo = uni.getStorageSync('userInfo')	
				this.$http.post('assemble/businessOrder/selectBusinessGroupOrders',{
					pageNo,
					orderType:'1',
					storeId:userInfo.storeId,
					status:this.status
				}).then((res)=>{
					if(res.data.obj){
						uni.hideLoading()
						this.orderList=this.orderList.concat(res.data.obj.list);
						this.pages = res.data.obj.totalPages-1;
					}else{
						this.orderList = []
					}
					
				}).catch((err)=>{
					console.log(err)
				})
			}
		},
		components:{
			myTab,
			orderItem
		}
	}
</script>

<style scoped>
	.order{
		width: 100%;
		background-color:  #ffffff;
	}

</style>
